# ########## General Setup ##############

IF(WIN32)
  target_link_libraries(spritecompiler "-mwindows" ${ALLEGRO_LIBRARIES} ${DIRECTX_LIBRARIES})
ELSE(WIN32)
  target_link_libraries(spritecompiler ${ALLEGRO_CONFIG_LIBS})
ENDIF(WIN32)

# ########## Resource compilation ########
IF(WIN32)
# Only Windows target needs resource compilation
# And MinGW is the only one that needs an explicit compile step
IF(MINGW)
  IF(CMAKE_CROSSCOMPILING)
    ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Sprite_Compiler_resource.obj
						  COMMAND i686-pc-mingw32-windres
							  -I${CMAKE_CURRENT_SOURCE_DIR}
							  -o ${CMAKE_CURRENT_BINARY_DIR}/Sprite_Compiler_resource.obj
							  -i${CMAKE_CURRENT_SOURCE_DIR}/Sprite_Compiler.rc
					      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Sprite_Compiler.rc
						  )
  ENDIF(CMAKE_CROSSCOMPILING)
  IF(NOT CMAKE_CROSSCOMPILING)
    ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Sprite_Compiler_resource.obj
						  COMMAND windres
							  -I${CMAKE_CURRENT_SOURCE_DIR}
							  -o ${CMAKE_CURRENT_BINARY_DIR}/Sprite_Compiler_resource.obj
							  -i${CMAKE_CURRENT_SOURCE_DIR}/Sprite_Compiler.rc
					      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Sprite_Compiler.rc
						  )
  ENDIF(NOT CMAKE_CROSSCOMPILING)
ENDIF(MINGW)
ENDIF(WIN32)

# ########## spritecompiler executable ##########
# Sources:
SET(spritecompiler_executable_SRCS
    main.c
)

IF(WIN32)
# Headers:
SET(spritecompiler_executable_HDRS
    Sprite_Compiler_rc.h
)
ELSE(WIN32)
# Headers:
SET(spritecompiler_executable_HDRS
)
ENDIF(WIN32)

# MSVC can natively handle Windows RC files
IF(MSVC)
SET(spritecompiler_executable_SRCS
    ${spritecompiler_executable_SRCS}
    Sprite_Compiler.rc
)
ENDIF(MSVC)

# actual target:
IF(WIN32)
IF(MINGW)
ADD_EXECUTABLE(spritecompiler ${spritecompiler_executable_SRCS} Sprite_Compiler_resource.obj)
ELSE(MINGW)
ADD_EXECUTABLE(spritecompiler ${spritecompiler_executable_SRCS})
ENDIF(MINGW)
ELSE(WIN32)
ADD_EXECUTABLE(spritecompiler ${spritecompiler_executable_SRCS})
ENDIF(WIN32)
# add install target:
INSTALL(TARGETS spritecompiler DESTINATION bin)
